<template>
  <div>
        <Divider />
        <!-- 顶部滑动条区域 -->
        <b-container>
            <!-- 类型 -->
            <div id="slider" class="mui-slider">
                <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                    <div class="mui-scroll">
                        <span class="mui-item" disabled>
                            类型:
                        </span>
                        <a :class="['mui-control-item', item.id==id ? 'mui-active' : '']" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="(item,i) in types" :key="i" @tap="getByType(item.value)">
                            {{ item.name }}
                        </a>
                    </div>
                </div>
            </div>
            <!-- 地区 -->
            <div id="slider" class="mui-slider">
                <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                    <div class="mui-scroll">
                        <span class="mui-item" disabled>
                            地区:
                        </span>
                        <a :class="['mui-control-item', i==0 ? 'mui-active' : '']" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="(item,i) in places" :key="i" @tap="getByPlace(item.value)">
                            {{ item.name }}
                        </a>
                    </div>
                </div>
            </div>
            <!-- 年代 -->
            <div id="slider" class="mui-slider">
                <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                    <div class="mui-scroll">
                        <span class="mui-item" disabled>
                            年代:
                        </span>
                        <a :class="['mui-control-item', i==0 ? 'mui-active' : '']" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="(item,i) in years" :key="i" @tap="getByYear(item.value)">
                            {{ item.name }}
                        </a>
                    </div>
                </div>
            </div>
            
            <!-- 内容区域 -->
            <b-row class="row-content">
                <b-col cols="6" sm="6" md="3" lg="3" v-for="item in list" :key="item.vId">
                    <div>
                        <b-card
                            :title="item.vName"
                            :img-src="item.vImg"
                            img-alt="Image"
                            img-top
                            tag="router-link"
                            :to="'/varietyInfo/' + item.vId"
                            style="max-width: 20rem;"
                            class="mb-2"
                        >
                            <b-card-text>
                            {{ item.vIntro }} 
                            </b-card-text>
                        </b-card>
                    </div>
                </b-col>
            </b-row>
            <div class="page-all">
              <Page :total="allPages.total" :page-size="pageSize" :current="pageNum" @on-change="changePage"  />
            </div>
        </b-container>
  </div>
</template>

<script>
// 1.导入 MUI 的JS 文件
import mui from '../../lib/mui/js/mui.min.js'

export default {
    data(){
        return{
            id:this.$route.params.id,
            types:[
                {id:1,name:"全部",value:""},
                {id:2,name:"美妆",value:"美妆"},
                {id:3,name:"旅行",value:"旅行"},
                {id:4,name:"演技",value:"演技"},
                {id:5,name:"经营",value:"经营"},
                {id:6,name:"游戏",value:"游戏"},
                {id:7,name:"其他",value:"其他"},
                ],  // 存放类型
            type:'',
            places:[
                {id:1,name:"全部",value:""},
                {id:2,name:"内地",value:"内地"},
                {id:3,name:"香港",value:"香港"},
                {id:4,name:"印度",value:"印度"},
                {id:5,name:"美国",value:"美国"}
            ], //存放地区
            place:'',
            years:[
                {id:1,name:"全部",value:""},
                {id:2,name:"2019",value:"2019"},
                {id:3,name:"2018",value:"2018"},
                {id:4,name:"2017",value:"2017"},
                {id:5,name:"2016",value:"2016"}
            ],  //存放年代
            year:'',
            list:[],
            pageNum:1,
            pageSize:4,
            allPages:[],
        }
    },
    mounted() { // 当 组件中的DOM结构被渲染好并放到页面中后，会执行这个 钩子函数
        // 如果要操作元素了，最好在 mounted 里面，因为，这里时候的DOM元素 是最新的
        // 2.初始化滑动插件
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });
    },
    created() {
        this.getList(this.pageNum,this.place,this.types[this.$route.params.id-1].value,this.year);
    },
    methods:{
        getList(pageNum,placeOne,typeOne,yearOne){
            let url = 'variety/findByType?vPlace=' + placeOne + '&vType=' + typeOne + '&vYear=' + yearOne + '&pageNo=' + pageNum + "&pageSize=" + this.pageSize;
            this.$http.get(url).then(result => {
                this.list = result.body.list;
                this.allPages = result.body;
            })
        },
        getByType(item){
            // 查看类型
            this.type = item;
            console.log(this.type);
            this.pageNum = 1;
            this.getList(this.pageNum,this.place,this.type,this.year);
        },
        getByPlace(item){
            // 查看地区
            this.place = item;
            this.pageNum = 1;
            this.getList(this.pageNum,this.place,this.type,this.year);
        },
        getByYear(item){
            // 查看年份
            this.year = item;
            this.pageNum = 1;
            this.getList(this.pageNum,this.place,this.type,this.year);
        },
        changePage(index){
            // 加载更多，页码改变的回调，返回改变后的页码
            this.pageNum = index;
            this.getList(this.pageNum,this.place,this.type,this.year);
        },
    },
    props:["parentId"],
}
</script>

<style lang="scss" scoped>
// 使用MUI的滑动组件时Chrome报的警告
*{
    touch-action:pan-y;
}
.page-all{
      display: flex;
      justify-content: center;
      margin-bottom: 1.5rem;
    }
.mui-segmented-control.mui-scroll-wrapper .mui-item{
    display: inline-block;
    width: auto;
    padding: 0 5px;
    border: 0;
    line-height: 38px;
    overflow: hidden;
    color:#666;
    text-align: center;
}
.mui-segmented-control.mui-scroll-wrapper .mui-control-item {
    display: inline-block;
    width: auto;
    padding: 0 20px;
    border: 0;
}
.row-content{
    min-height:347px;
}
.card-body{
        padding: 0.5rem;
        .card-title {
            margin-bottom: 0rem;
            font-size: 0.9rem;
            font-weight: bold;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
        .card-text{
            font-size: 0.8rem;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }
    }
</style>